package cz.acies.organizer.http.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cz.acies.organizer.data.process.CalendarProcessor;

public class CalendarConnector extends HttpServlet
{
	private static final long serialVersionUID = -6921203750437012513L;

	public CalendarConnector() {
		super();
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			PrintWriter out = response.getWriter();
			request.setCharacterEncoding("UTF-8");
			response.setCharacterEncoding("UTF-8");
			response.setContentType("application/json");
			/*
			Map<String, Object> params = new HashMap<String, Object>();
			Enumeration<String> e = request.getParameterNames();
			while (e.hasMoreElements()) {
				String key = e.nextElement();
				params.put(key, request.getParameter(key));
			}
			String processId = (String) params.get("processId");
			*/
			//System.out.println("CalendarConnector.doPost().params: " + params);
			CalendarProcessor processor = new CalendarProcessor();
			processor.execute(request, response);
			out.flush();
			out.close();
		} catch (Exception exc) {
			exc.printStackTrace();
		}
	}

}
